<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Health Care System</title>

<link href="loginsystem.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="loginsystem.js"></script>

<script>
	function loadXMLDoc() {
		alert("111111111111111");
		var elem = document.getElementById("loginform").elements;
		var params = "";
		url = document.getElementById("loginform").action;

		var xmlhttp;

		for (var i = 0; i < elem.length; i++) {
			if (elem[i].tagName == "SELECT") {
				params += elem[i].name
						+ "="
						+ encodeURIComponent(elem[i].options[elem[i].selectedIndex].value)
						+ "&";
			} else {
				params += elem[i].name + "="
						+ encodeURIComponent(elem[i].value) + "&";
			}
		}		

		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				//document.write(xmlhttp.responseText);
				//console.log("xml="+xmlhttp.responseXML);
				var result;
				var userid;
				var roleid;

				x = xmlhttp.responseXML.getElementsByTagName("login");
				
				for (i = 0; i < x.length; i++) {
					xx = x[i].getElementsByTagName("result");
					result = xx[0].firstChild.nodeValue;
					xx = x[i].getElementsByTagName("userid");
					userid = xx[0].firstChild.nodeValue;
					xx = x[i].getElementsByTagName("roleId");
					roleid = xx[0].firstChild.nodeValue;
				}
				
				if (result == "Success") {
					
					if (roleid == "1" || roleid == "2")
						window.location.href = "officermain.html?userid="
								+ userid;
					else if (roleid == "3")
						window.location.href = "doctormain.html?userid="
								+ userid;
					else if (roleid == "4")
						window.location.href = "assistantmain.html?userid="
								+ userid;
					else if (roleid == "5")
						window.location.href = "patientmain.html?userid="
								+ userid;
				} else {
					document.getElementById("Result").innerHTML = "The user name or password you entered is incorrect.";
					document.getElementById("Result").style.color = "red";
				}
			}
		}

		xmlhttp.open("POST", url, true);
		//xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
		xmlhttp.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		//xmlhttp.setRequestHeader("Content-length", params.length);
		//xmlhttp.setRequestHeader("Connection", "close");
		//console.log("params="+params);
		xmlhttp.send(params);
	}
</script>
</head>
<body>
	<div id="head">
	  	<img src="../images/Logos/Logo-1-circle-wangqi.JPG" alt="" width="10%"/>
	</div>  
	
	<div id="login" >		
		<div id="signhead">
		<!-- 
			<h1>Sign In</h1>
		 -->	
		</div>
		<div id="signbody">
			<form id="loginform" method="post" action="../LoginService" onkeypress="if(event.keyCode==13||event.which==13){return false;}">
				
				<input id="userId" name="username" type="text" placeholder="Username" class="inputbox"
					style="width:100%; height:30px; font-family: 'Trebuchet MS', Arial, Verdana, sans-serif; font-size:15px; color:grey;" /><br /> <br />				
				<input id="pwd" name="password" type="password" placeholder="Password" class="inputbox"
					style="width:100%; height:30px; font-family: 'Trebuchet MS', Arial, Verdana, sans-serif; font-size:15px; color:grey;" /><br /> <br />						
			</form>
			<div id="Result"></div>
			<p><div id="submit" onclick="submitLoginForm()">Sign in</div></p>
		</div>

		<div id="forgotpsw">
			<a href="#" id="flink">Forgot Password?</a>
		</div>
	</div>
	<address>
		Email: <a href="mailto:vanier-college@gamil.com">Vanier College</a><br />
		Addr: 821 Sainte-Croix Montr&#233al, Qu&#233bec H4L 3X9 Canada <b>Tel:
			514.744.7500</b> <br /> Copyright &#169 L&#233o 2014 All Rights Reserved
		<hr color=#A4D0F0 width="800" />
		<a href="#">About Us</a> &#124 <a href="Contact/Contact.htm"
			target="window">Contact Us</a>
	</address>

</body>
</html>